-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new checker http-const
#155
Conversation
This probably deserves a bit of refactoring. |
Pull Request Test Coverage Report for Build 9659794485Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, it would be great to have this linter
I was thinking about coding it, but you did it.
It's great!!!
@@ -56,9 +56,14 @@ func isTypedIntNumber(e ast.Expr, v int, types ...string) bool { | |||
return false | |||
} | |||
|
|||
func isIntNumber(e ast.Expr, v int) bool { | |||
func safeTypedBasicLit(e ast.Expr, typ token.Token) (*ast.BasicLit, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure about the name, but thanks I had also noticed this could be refactored into a dedicated function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is a type-safe BasicLit
, I named it this way .
Feel free to change it if you have a better idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so lame at wording. I'm only able to argue when I find a wording, but I'm never able to find a descent one to suggest 😅
} | ||
|
||
var httpStatusCode = map[string]string{ | ||
strconv.Itoa(http.StatusContinue): "http.StatusContinue", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should consider performance for this
I would have used a httpStatusCode = map[int]string{
so no, strconv.Itoa here
but only when needed in the code, you can also create a dedicated testing helper if your prefer
but current code looks strange to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just the way it's done in usestdlibvars
, see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed it 😅. The code is so strange 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Anton will provide his guidance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antonboom it's me the serial mention guy 😅😁
What are your thoughts about this?
The fact the code imported from usedstdvars is a bit strange
internal/checkers/http_const.go
Outdated
} | ||
} | ||
if len(suggestedFixes) > 0 { | ||
return &analysis.Diagnostic{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better if newDiagnostic func was able to handle an array of suggestedFix instead of one . But that's for a dedicated PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
Pull Request Test Coverage Report for Build 9668183301Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9668248204Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9668312351Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9668623785Details
💛 - Coveralls |
internal/checkers/http_const.go
Outdated
} | ||
if bt, ok := safeTypedBasicLit(call.Args[4], token.INT); ok { | ||
currentVal := bt.Value | ||
key := strings.ToUpper(currentVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for this, please add tests for for lower case "get" or Pascal case (Get) and all other methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between testify assert Method, http method and http status, that’s going to be a huge matrix to cover, any idea on how to cover it with a simple solution ?
Pull Request Test Coverage Report for Build 9669768290Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9669932292Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9669999628Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9670110548Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9673263571Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to send this. It was pending
I now understand why @ldez (hi 👋) expects PR to do not rewriting history during code review. It's something I have been doing for a while, even in this project. But now I'm facing the way @mmorel-35 does, which I would have done too, I can see how difficult it is yo track the changes made between each iterations. Here there is only one commit, and I have to read everything again and again instead of seeing the small changes made by each reviews I repeat it's something I have done many times, even recently, so I don't blame you @mmorel-35, but now I understand Ludovic's guidance |
@mmorel-35 I have no idea what you changed with your last commit. I reviewed everything and spotted things I found. But I have no idea if it's new code or not. |
Pull Request Test Coverage Report for Build 9674262358Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9674319119Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9674373889Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9674389614Details
💛 - Coveralls |
@ccoVeille , |
Thanks for taking my workflow suggestion into account. I do hate to see a log like that. But for reviewing it's way simpler. Please note, I'm OK with you to rearrange the commits in the way you intend. But many only once you get an approval for the PR. Anx with a message like in the PR like "squashing previously reviewd changes" I dislike squashed PR too, that's why I'm suggesting that. Also squashing when merging would nuke the respective contribution of each developer. Think about Anton "maintainer review" commit. At least, GitHub doesn't nuke authors who contributed as it adds the But I do think it's way easier for reviewing with atomic and iterative commits. Thanks again for baring with me |
Pull Request Test Coverage Report for Build 9695506618Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9696894260Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks
internal/testgen/gen_http_const.go
Outdated
{Fn: "HTTPStatusCode", Argsf: `httpOK, http.MethodGet, "/index", nil, http.StatusOK`}, | ||
{Fn: "HTTPBodyContains", Argsf: `httpHelloName, http.MethodGet, "/", url.Values{"name": []string{"World"}}, "Hello, World!"`}, | ||
}, | ||
IgnoredAssertions: []Assertion{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmorel-35 I don't know if you saw this one
Pull Request Test Coverage Report for Build 9702352952Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9723300042Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9723821079Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
May I suggest you to squash/fix up now? To reduce the number of commits
Pull Request Test Coverage Report for Build 9726718535Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9798875390Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9799153037Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9826249234Details
💛 - Coveralls |
2 similar comments
Pull Request Test Coverage Report for Build 9826249234Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9826249234Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9826674310Details
💛 - Coveralls |
2 similar comments
Pull Request Test Coverage Report for Build 9826674310Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9826674310Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 10704164578Details
💛 - Coveralls |
Co-Authored-By: ccoVeille <[email protected]>
5004c06
to
1994ec7
Compare
Closes #141